from fastapi import FastAPI
from pydantic import BaseModel

from fastapi.staticfiles import StaticFiles
from starlette.middleware.cors import CORSMiddleware

app12 = FastAPI()
app12.mount("/static", StaticFiles(directory="../static"), name="static")
# 添加CORS中间件
app12.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # 在生产环境中应该指定具体的域名
    allow_credentials=True, # 是否认证
    allow_methods=["*"],
    allow_headers=["*"],
)


class TeacherIn(BaseModel):
    name :str
    username :str
    password :str

@app12.post('/teacher')
async def addTeacher(teacher: TeacherIn):
    print(teacher.name)
    print(teacher.username)
    print(teacher.password)
    return {
        'teacher':teacher
    }

if __name__ == '__main__':
    import uvicorn
    uvicorn.run(app12, host='127.0.0.1', port=8000)